package guiLayer;

import java.awt.CardLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;

import net.miginfocom.swing.MigLayout;

public class ItemTab1 extends JPanel implements ActionListener {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private final static String PRODUCTCARD = "Produkt (alm. vare)";
	private final static String COMPOSITIONCARD = "Komposition (sammensat vare)";
	private final JPanel cardContainer;
	private final JComboBox<Object> cbItemType;

	/**
	 * Create the panel.
	 */
	public ItemTab1() {
		setBorder(new EmptyBorder(10, 10, 10, 10));
		setLayout(new MigLayout("center", "[900px]", "[70px][::450px,grow][40px]"));

		// Top panel
		JPanel itemType = new JPanel();
		itemType.setBorder(new TitledBorder(null, "Vare type", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		add(itemType, "cell 0 0,growx,aligny top");
		itemType.setLayout(new MigLayout("leading", "[grow]", "[30px]"));

		cbItemType = new JComboBox<Object>();
		cbItemType.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String cardName = (String)cbItemType.getSelectedItem();
				CardLayout cl = (CardLayout)(cardContainer.getLayout());
				cl.show(cardContainer, cardName);
			}
		});
		cbItemType.setModel(new DefaultComboBoxModel<Object>(new String[] {PRODUCTCARD, COMPOSITIONCARD}));
		cbItemType.setEditable(false);
		itemType.add(cbItemType, "cell 0 0,grow");

		// Middle card panel
		cardContainer = new JPanel();
		cardContainer.setBorder(new TitledBorder(null, "Vare egenskaber", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		add(cardContainer, "cell 0 1,grow");
		cardContainer.setLayout(new CardLayout(0, 0));

		JPanel productCard = new ItemCardProductCreation();
		cardContainer.add(productCard, PRODUCTCARD);

		JPanel compositionCard = new ItemCardCompositionCreation();
		cardContainer.add(compositionCard, COMPOSITIONCARD);

		//Bottom panel with buttons.
		JPanel buttonPanel = new JPanel();
		add(buttonPanel, "cell 0 2,alignx trailing,aligny top");
		buttonPanel.setLayout(new MigLayout("", "[100px][100px]", "[25px]"));

		JButton btnCancel = new JButton("Annuller");
		buttonPanel.add(btnCancel, "cell 0 0,grow");

		JButton btnSave = new JButton("Gem");
		buttonPanel.add(btnSave, "cell 1 0,grow");
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub

	}		
}